import { nsList } from '../api/ns'
import { dsClone } from '../api/ds'
export const dsCloneData = {
  data(){
    return {
      cloneOpen: false,
      cloneForm: {
        title: "克隆数据",
        targetNs: '',
        sourceNs: '',
        cloneType: 'TERMINATE_IMPORT',
        dataCloneScope: 'SELF',
        bizType: '',
        sourceInfos: []
      },
      multipleCloneInfo: [],
    }
  },
  methods:{
    clickClone(ns,bizType) {
      if (this.multipleSelection.length === 0) {
          this.$message({
              type: 'info',
              message: '请选择需要克隆的数据'
          })
          this.cloneOpen = false
      } else {
          this.cloneOpen = true
          this.cloneForm.sourceNs = ns
          this.cloneForm.bizType = bizType
          this.cloneForm.sourceInfos = this.multipleCloneInfo.map(item => item);
          this.$nextTick(() => {
            this.$refs.cloneRef.init(bizType,this.cloneForm)
          })
      }
    }
  }
}

export const nsData = {
  data(){
    return {
      ns: 'public',
      nss: []
    }
  },
  methods:{
    /**
     * 查询名称空间列表
     */
    getNsList() {
      nsList(this.ns).then((res) => {
          this.nss = res.data;
      })
    },
  },

}

export const commonData = {
  data(){
    return {
      selectionFlag: false,
      pageData: {
        currPage: 1,
        list: [],
        pageSize: 10,
        totalCount: 0,
        totalPage: 0
      },
      multipleSelection: [],
      page: {
          page: 1,
          limit: 10
      }
    }
  },
  methods:{
    hanldeChangeView(url,queryParams){
      this.$bus.$emit('changeView',url,queryParams)
    },
    /**
     * 设置当前页条数
     * @param { } limit 
     */
    handleSizeChange(limit) {
        this.page.limit = limit
        this.getPageList()
    },
    /**
     * 设置当前第几页
     * @param {} page 
     */
    handleCurrentChange(page) {
        this.page.page = page
        this.getPageList()
    },
    /**
     * 单个删除
     * @param {} selection 
     */
    handleDel(selection) {
        this.multipleSelection = []
        this.multipleSelection.push(selection)
        this.handleBatchDel()
    },
    /**
     * 批量删除，由组件覆盖重写
     */
    handleBatchDel(){
      console.log("...组件覆盖删除方法...")
    },
    /**
     * 分页查询，由组件覆盖重写
     */
    handleQuery() {
      this.getPageList()
    },
    /**
     * 分页查询，由组件覆盖重写
     */
    getPageList(){
      console.log("...组件覆盖分页方法...")
    }
  }
}
